﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DTO
{
    /// <summary>
    /// This class represents the tag structure of a webpage.
    /// </summary>
    public class Webtag
    {
        #region Attributes
        int id;
        Webtag parent;
        string name;
        string xPath;
        string text;
        string originalURL;
        List<Webtag> children;
        int isDup;
        int webpageID;
        #endregion

        #region Properties
        /// <summary>
        /// ID of the webpage that contains this tag
        /// </summary>
        public int WebpageID
        {
            get { return webpageID; }
            set { webpageID = value; }
        }

        /// <summary>
        /// OriginalURL of anchor tag
        /// </summary>
        public string OriginalURL
        {
            get { return originalURL; }
            set { originalURL = value; }
        }

        /// <summary>
        /// List of all children tag of this current tag.
        /// </summary>
        public List<Webtag> Children
        {
            get { return children; }
            set { children = value; }
        }

        /// <summary>
        /// The parent tag of the current tag.
        /// </summary>
        public Webtag Parent
        {
            get { return parent; }
            set { parent = value; }
        }

        /// <summary>
        /// ID of this current tag
        /// </summary>
        public int ID
        {
            get { return id; }
            set { id = value; }
        }

        /// <summary>
        /// xPath that represents the path from root tag to this current tag.
        /// </summary>
        public string XPath
        {
            get { return xPath; }
            set { xPath = value; }
        }

        /// <summary>
        /// The tag name of this tag.
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        /// <summary>
        /// The inner text of this tag. Empty string if this tag contains other tag(s) or this tag has no text inside.
        /// </summary>
        public string Text
        {
            get { return text; }
            set { text = value; }
        }

        public int IsDup
        {
            get { return isDup; }
            set { isDup = value; }
        }
        #endregion

        #region Constructors
        public Webtag()
        {
            this.id = 0;
            this.originalURL = string.Empty;
            this.children = new List<Webtag>();
        }

        public Webtag(string name, string text, string xpath, string originalURL)
        {
            this.id = 0;
            this.name = name;
            this.text = text;
            this.xPath = xpath;
            this.originalURL = originalURL;
            this.children = new List<Webtag>();
        }

        public Webtag(Webtag input)
        {
            this.id = input.ID;
            if (input.Parent != null)
            {
                this.parent = new Webtag(input.Parent);
            }
            else
            {
                this.parent = null;
            }
            this.name = input.Name;
            this.xPath = input.xPath;
            this.text = input.Text;
            this.originalURL = input.OriginalURL;
            this.children = new List<Webtag>(input.Children);
            this.isDup = this.IsDup;
            this.webpageID = this.WebpageID;
        }
        #endregion
    }
}
